package com.xnck.example.jertest.service;

import com.xnck.example.jertest.annotation.AspectRoundNoTran;
import com.xnck.example.jertest.annotation.AspectRoundTran;
import com.xnck.example.jertest.dao.DicDao;
import com.xnck.example.jertest.entity.DicInfo;
import com.xnck.example.jertest.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestService {

    @Autowired
    private DicDao dicDao;

    public String getTestMessage() {
        return "由TestService返回信息";
    }

    @AspectRoundTran
    @Transactional(rollbackFor = Exception.class)
    public DicInfo createDic(String name) {
        if (name.contains("测试")) {
            return dicDao.insert(RandomUtil.getShortUUID(), name);
        } else {
            dicDao.insert(RandomUtil.getShortUUID(), name);
            return null;
        }
    }
}
